package com.hf.eagle.web.listener;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.hf.eagle.domain.SiteLink;
import com.hf.eagle.service.Facade;

public class SessionSiteLinkListener implements HttpSessionListener {

	public void sessionCreated(HttpSessionEvent httpSessionEvent) {
		ServletContext servletContext = httpSessionEvent.getSession().getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
		Facade facade = (Facade) wac.getBean("facade");

		SiteLink siteLink = new SiteLink();
		siteLink.setIs_del(0);
		siteLink.setMod_id((long) 4200);
		siteLink.getRow().setFirst(0);
		siteLink.getRow().setCount(5);
		List<SiteLink> siteLinks = facade.getSiteLinkService().getSiteLinkPaginatedList(siteLink);

		httpSessionEvent.getSession().setAttribute("siteLinks", siteLinks);
	}

	public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
		httpSessionEvent.getSession().setAttribute("siteLinks", null);
	}
}
